package com.car.web.controller.admin_t;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.car.util.*;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.car.bean.GridObj;
import com.car.bean.PageObj;
import com.car.dal.dao.ask.AskDao;
import com.car.dal.dao.client.TgClientDao;
import com.car.dal.dao.department.TgDepartmentDao;
import com.car.dal.dao.from.FromUserDao;
import com.car.dal.dao.office.TgOfficeDao;
import com.car.dal.dao.source.TgSourceDao;
import com.car.dal.dao.spread.JsSpreadDao;
import com.car.dal.dao.sudent.StudentDao;
import com.car.dal.dao.user.UserDao;
import com.car.dal.dao.user.UserinfoDao;
import com.car.dal.dao.usergroup.TgUsergroupDao;
import com.car.dal.dao.vote.JsVoteDao;
import com.car.dal.dao.work.TgworkDao;
import com.car.dal.object.AskMsg;
import com.car.dal.object.Items;
import com.car.dal.object.JsAsk;
import com.car.dal.object.JsFromUser;
import com.car.dal.object.JsSpread;
import com.car.dal.object.JsVote;
import com.car.dal.object.Scores;
import com.car.dal.object.TgClient;
import com.car.dal.object.TgSource;
import com.car.dal.object.TgStudent;
import com.car.dal.object.TgUser;
import com.car.dal.object.TgUserinfo;
import com.car.util.JsonExecutor.JsonBiz;
import com.car.util.WebExecutor.Biz;
import com.car.web.controller.base.BaseController;
import com.car.web.controller.base.BaseVo;
import com.car.web.controller.index.LoginVo;
import com.ssi.utils.SsiUtils;

/**
 * 登录控制
 *
 * @author Administrator
 */
@Controller
@RequestMapping("/admin")
public class AdminController extends BaseController {

    private static final Logger logger = Logger
            .getLogger(AdminController.class);
    @Resource
    private UserDao userDao;
    @Resource
    private TgworkDao workDao;
    @Resource
    private TgUsergroupDao tgUsergroupDao;
    @Resource
    private TgDepartmentDao tgDepartmentDao;
    @Resource
    private UserinfoDao userinfoDao;
    @Resource
    private TgOfficeDao tgOfficeDao;
    @Resource
    private AskDao askDao;
    @Resource
    private JsVoteDao voteDao;
    @Resource
    private JsSpreadDao spreadDao;
    @Resource
    private FromUserDao fromUserDao;
    @Resource
    private TgClientDao clientDao;
    @Resource
    private StudentDao studentDao;
    @Resource
    private TgSourceDao sourceDao;
    @Resource
    private JsVoteDao jsVoteDao;

    //初始欢迎页面
    @RequestMapping(value = "/admin_hello")
    public ModelAndView struct_info(ModelMap modelMap, final LoginVo loginVo,
                                    final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                return result;
            }
        });
        return new ModelAndView("admin_t/admin_hello", modelMap);
    }

    @RequestMapping(value = "/ask_list")
    public ModelAndView ask_list(ModelMap modelMap, final BaseVo vo,
          final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            @SuppressWarnings("unchecked")
            public Result process() {
                Result result = new ResultSupport(true);
                JsAsk ask = new JsAsk();

                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }

                PageObj pageObj = PageUtil.createPages(8, vo.getCurrPage());
                GridObj mesObj = askDao.GetList(ask, pageObj);

                List<JsAsk> list = (List<JsAsk>) mesObj.getRoot();
                if (list != null && list.size() > 0) {
                    for (JsAsk jsAsk : list) {
                        String desc = jsAsk.getDescs();
                        if (desc != null && !"".equals(desc)) {
                            boolean flag = StringUtil.getHanzi(desc);
                            if (!flag) {
                                try {
                                    byte[] bytes = StringUtil.hexDecode(desc);
                                    jsAsk.setDescs(new String(bytes, "UTF-8"));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                        jsAsk.setModeDate(new Date(jsAsk.getMdate() * 1000));
                    }
                }

                Page page = PageUtil.createPage(8, currPage, mesObj.getTotalProperty().intValue());
                result.setDefaultModel("list", list);
                result.setDefaultModel("page", page);
                return result;
            }
        });
        return new ModelAndView("admin_t/ask_list", modelMap);
    }

    @RequestMapping(value = "/ask_add")
    public ModelAndView ask_add(ModelMap modelMap, final BaseVo vo,
                                final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String keyname = request.getParameter("keyname");
                if (keyname != null && !"".equals(keyname)) {
                    JsAsk ask = new JsAsk();
                    ask.setKeyname(keyname);
                    List<JsAsk> askList = askDao.findByExample(ask);
                    if (askList != null && askList.size() > 0) {
                        ask = askList.get(0);
                    }
                    if (ask != null) {
                        String desc = ask.getDescs();
                        if (desc != null && !"".equals(desc)) {
                            boolean flag = StringUtil.getHanzi(desc);
                            if (!flag) {
                                try {
                                    byte[] bytes = StringUtil.hexDecode(desc);
                                    ask.setDescs(new String(bytes, "UTF-8"));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                        String item = ask.getItem();
                        if (item != null && !"".equals(item)) {
                            try {
                                List<AskMsg> askIList = new ArrayList<AskMsg>();

                                JSONObject obj = JSONObject.fromObject(item);

                                for (int j = 0; j < 15; j++) {
                                    JSONObject ask0 = obj.getJSONObject("ask" + j);
                                    if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                        String id0 = ask0.getString("id");
                                        String topic0 = ask0.getString("topic");
                                        JSONArray items0 = ask0.getJSONArray("items");
                                        AskMsg askMsg = new AskMsg();
                                        askMsg.setId(id0);
                                        askMsg.setTopic(topic0);
                                        if (items0 != null && items0.size() > 0) {
                                            List<Items> itemList = new ArrayList<Items>();
                                            for (int i = 0; i < items0.size(); i++) {
                                                Items items = new Items();
                                                JSONObject o = JSONObject.fromObject(items0.get(i));
                                                items.setQ(o.getString("q"));
                                                items.setI(o.getString("i"));
                                                itemList.add(items);
                                            }
                                            askMsg.setItemList(itemList);
                                        }
                                        askIList.add(askMsg);
                                    }
                                }
                                result.setDefaultModel("askIList", askIList);

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        String score = ask.getScore();
                        if (score != null && !"".equals(score)) {
                            try {
                                List<AskMsg> askSList = new ArrayList<AskMsg>();

                                JSONObject obj = JSONObject.fromObject(score);

                                for (int j = 0; j < 15; j++) {
                                    JSONObject ask0 = obj.getJSONObject("ask" + j);
                                    if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                        String id = ask0.getString("id");
                                        String topic = ask0.getString("topic");
                                        JSONArray source = ask0.getJSONArray("source");
                                        JSONArray scores = ask0.getJSONArray("scores");
                                        AskMsg askMsg = new AskMsg();
                                        askMsg.setId(id);
                                        askMsg.setTopic(topic);
                                        askMsg.setSource(source);
                                        if (scores != null && scores.size() > 0) {
                                            List<Scores> scoresList = new ArrayList<Scores>();
                                            for (int i = 0; i < scores.size(); i++) {
                                                Scores sco = new Scores();
                                                JSONObject o = JSONObject.fromObject(scores.get(i));
                                                sco.setS1(o.getString("s1"));
                                                sco.setS2(o.getString("s2"));
                                                sco.setR(o.getString("r"));
                                                scoresList.add(sco);
                                            }
                                            askMsg.setScoresList(scoresList);
                                        }
                                        askSList.add(askMsg);
                                    }
                                }
                                result.setDefaultModel("askSList", askSList);

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    result.setDefaultModel("ask", ask);
                }
                return result;
            }
        });
        return new ModelAndView("admin_t/ask_add", modelMap);
    }

    @RequestMapping(value = "/ask_add_go")
    public ModelAndView ask_add_go(ModelMap modelMap, final BaseVo vo,
                                   final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");
                String topic = request.getParameter("topic");
                String descs = request.getParameter("descs");
                String item = request.getParameter("item");
                String score = request.getParameter("score");
                JsAsk ask = new JsAsk();
                ask.setTopic(topic);
                ask.setDescs(descs);
                ask.setItem(item);
                ask.setScore(score);
                if (id != null && !"".equals(id)) {
                    ask.setId(Long.valueOf(id));
                    askDao.update(ask);
                } else {
                    askDao.insert(ask);
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }
    /**
     * @Description:问卷资源分配
     * @author: Hqd
     * @date: 2017年11月10日 下午1:54:57 
     * @return
     */
    @RequestMapping(value = "/ask_answer_list")
    public ModelAndView struct_info(ModelMap modelMap, final BaseVo vo,
                                    final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String topic = request.getParameter("topic");
                String contact = request.getParameter("contact");
                String address = request.getParameter("address");
                String sname = request.getParameter("sname");
                String source = request.getParameter("source");
                String startTime = request.getParameter("stardate");
                String endTime = request.getParameter("enddate");
                String state = request.getParameter("state");
                String st_type = request.getParameter("st_type");

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                JsVote vote = new JsVote();
                if (topic != null && !"".equals(topic)) {
                    vote.setTopic(topic);
                }
                if (contact != null && !"".equals(contact)) {
                    vote.setPhone(contact);
                }
                if (address != null && !"".equals(address)) {
                    vote.setCity(address);
                }
                if (sname != null && !"".equals(sname)) {
                    vote.setSpname(sname);
                }
                if (source != null && !"".equals(source)) {
                    vote.setSource(source);
                }
                if (st_type != null && !"".equals(st_type)) {
                    vote.setSt_type(Integer.valueOf(st_type));
                }
                if (startTime != null && !"".equals(startTime)) {
                    result.setDefaultModel("startTime", startTime);
                    try {
                        vote.setStartTime(sdf.parse(startTime).getTime() / 1000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (endTime != null && !"".equals(endTime)) {
                    result.setDefaultModel("endTime", endTime);
                    try {
                        vote.setEndTime(sdf.parse(endTime).getTime() / 1000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (state != null && !"".equals(state)) {
                    if (state.equals("1")) {
                        vote.setState1(state);
                    } else if (state.equals("2")) {
                        vote.setState2(state);
                    }
                }

                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }
                Integer total = voteDao.getVoCountByType(vote);
                Page page = PageUtil.createPage(8, currPage, total);
                List<JsVote> list = voteDao.getVolistByType(vote, page);
                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                if (list != null && list.size() > 0) {
                    for (JsVote vo : list) {
                        vo.setCreateTime(sdf1.format(new Date(vo.getCdate() * 1000)));
                    }
                }

                result.setDefaultModel("vote", vote);
                result.setDefaultModel("page", page);
                result.setDefaultModel("contact", contact);
                result.setDefaultModel("source", source);
                result.setDefaultModel("address", address);
                result.setDefaultModel("list", list);
                result.setDefaultModel("topic", topic);
                result.setDefaultModel("startTime", startTime);
                result.setDefaultModel("endTime", endTime);
                result.setDefaultModel("sname", sname);
                return result;
            }
        });
        return new ModelAndView("admin_t/ask_answer_list", modelMap);
    }

    @RequestMapping(value = "/deleteVoteById")
    public ModelAndView deleteVoteById(ModelMap modelMap, final BaseVo vo,
                                       final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String ids = request.getParameter("ids");

                JsVote vote = new JsVote();
                String[] id = ids.split(",");
                if (id != null && id.length > 0) {
                    for (int i = 0; i < id.length; i++) {
                        vote.setId(Long.valueOf(id[i]));
                        vote.setSt_type(2);
                        voteDao.update(vote);
                        result.setDefaultModel("msg", "1");
                    }
                } else {
                    result.setDefaultModel("msg", "0");
                }

                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }

    @RequestMapping(value = "/deleteFromUserById")
    public ModelAndView deleteFromUserById(ModelMap modelMap, final BaseVo vo,
                                           final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String ids = request.getParameter("ids");

                JsFromUser fromUser = new JsFromUser();
                String[] id = ids.split(",");
                if (id != null && id.length > 0) {
                    for (int i = 0; i < id.length; i++) {
                        fromUser.setId(Long.valueOf(id[i]));
                        fromUser.setSt_type(2);
                        fromUserDao.update(fromUser);
                        result.setDefaultModel("msg", "1");
                    }
                } else {
                    result.setDefaultModel("msg", "0");
                }

                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }

    @RequestMapping(value = "/ask_allot")
    public ModelAndView ask_allot(ModelMap modelMap, final BaseVo vo,
                                  final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");
                String look = request.getParameter("look");

                JsVote vote = new JsVote();
                if (id != null && !"".equals(id)) {
                    vote = voteDao.findById(JsVote.class, Long.valueOf(id));
                    if (vote != null) {
                        JsAsk ask = new JsAsk();
                        ask.setKeyname(vote.getAsk());
                        List<JsAsk> list = askDao.findByExample(ask);
                        if (list != null && list.size() > 0) {
                            vote.setVoteName(list.get(0).getTopic());
                            vote.setAskid(list.get(0).getId());
                        }

                        String desc = vote.getDesc1();
                        if (desc != null && !"".equals(desc)) {
                            boolean flag = StringUtil.getHanzi(desc);
                            if (!flag) {
                                try {
                                    byte[] bytes = StringUtil.hexDecode(desc);
                                    vote.setDescs(new String(bytes, "UTF-8"));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                        TgClient client = new TgClient();

                        Long a = 0L;
                        Long b = 0L;
                        Long c = 0L;
                        if (vote.getPhone() != null && !"".equals(vote.getPhone().trim())) {
                            TgClient client1 = new TgClient();
                            client1.setPhone(vote.getPhone());
                            client.setPhone(vote.getPhone());
                            a = clientDao.countEqual(client1);
                        }
                        if (vote.getEmail() != null && !"".equals(vote.getEmail().trim())) {
                            TgClient client2 = new TgClient();
                            client2.setWeixin(vote.getEmail());
                            client.setWeixin(vote.getEmail());
                            b = clientDao.countEqual(client2);
                        }
                        if (vote.getQq() != null && !"".equals(vote.getQq().trim())) {
                            TgClient client3 = new TgClient();
                            client3.setQq(vote.getQq());
                            client.setQq(vote.getQq());
                            c = clientDao.countEqual(client3);
                        }

                        Long total = a + b + c;
                        if (total > 0) {
                            result.setDefaultModel("total", "1");
                            List<TgClient> clist = clientDao.getClientallot(client);
                            result.setDefaultModel("clist", clist.get(0));
                        }
                    }
                }
                TgUserinfo user = new TgUserinfo();
                user.setJob("课程顾问");
                List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(user);

                TgUserinfo user1 = new TgUserinfo();
                user1.setJob("在线课程顾问");
                List<TgUserinfo> uList1 = userinfoDao.getUserInfoByUserInfo(user1);

                result.setDefaultModel("uList", uList);
                result.setDefaultModel("uList1", uList1);
                result.setDefaultModel("look", look);
                result.setDefaultModel("vote", vote);
                return result;
            }
        });
        return new ModelAndView("admin_t/ask_allot", modelMap);
    }

    @RequestMapping(value = "/ask_allot_go")
    public ModelAndView ask_allot_go(ModelMap modelMap,
                                     final BaseVo vo, final HttpServletRequest request,
                                     final HttpServletResponse response) throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("voteId");
                String user = request.getParameter("user");
                String descs = request.getParameter("desc");
                String clientkey = request.getParameter("clientkey");

                TgUser users = UserUtil.getUserFromCookies();
                if (id != null && !"".equals(id)) {
                    JsVote vote = new JsVote();
                    vote = voteDao.findById(JsVote.class, Long.valueOf(id));
                    if (vote != null) {
                        vote.setUsername(user);
                        vote.setTo_time(new Date());
                        vote.setGo_username(users.getUsername());
                        voteDao.update(vote);

                        JsAsk jsask = new JsAsk();
                        jsask.setKeyname(vote.getAsk());
                        String quests = "";
                        List<JsAsk> aklist = askDao.findByExample(jsask);
                        if (aklist != null && aklist.size() > 0) {
                            JSONObject json = new JSONObject();
                            jsask = aklist.get(0);
                            json.put("name", jsask.getTopic());
                            if (jsask.getKeyname().equals("zice")) {
                                json.put("url", "http://www.taleu.com/zice.html?id=" + vote.getId());
                            } else if (jsask.getKeyname().equals("wenjuan")) {
                                json.put("url", "http://www.taleu.com/wenjuan.html?id=" + vote.getId());
                            } else {
                                json.put("url", "http://a.jingsiedu.com/admin/ask.htm?key=" + vote.getKeyname());
                            }
                            JSONArray array = new JSONArray();
                            array.add(json);
                            quests = array.toString();
                        }

                        String spcode = "";
                        JsSpread spread = new JsSpread();
                        spread.setSpcode(vote.getSpcode());
                        List<JsSpread> splist = spreadDao.findByExample(spread);
                        if (splist != null && splist.size() > 0) {
                            spcode = splist.get(0).getSource();
                        }

                        TgClient client = new TgClient();
                        client.setRawusername(vote.getUsername());
                        client.setLodusername(user);
                        client.setNickname("匿名");
                        client.setSource(spcode);
                        client.setPhone(vote.getPhone());
                        client.setEmail(vote.getEmail());
                        client.setQq(vote.getQq());
                        client.setAddress(vote.getCity());
                        client.setQuests(quests);
                        client.setDescs(descs);
                        client.setType(1);
                        client.setFrom_id(vote.getId());
                        client.setCdate(new Date().getTime() / 1000);
                        client.setMdate(new Date().getTime() / 1000);
                        client.setRdate(new Date().getTime() / 1000);
                        if (clientkey != null && !"".equals(clientkey)) {
                            client.setKeyname(clientkey);
                            clientDao.update(client);
                        } else {
                            client.setKeyname(SsiUtils.randomUUID());
                            clientDao.insert(client);
                        }
                    }
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }

    @RequestMapping(value = "/ask")
    public ModelAndView ask(ModelMap modelMap, final BaseVo vo,
                            final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String key = request.getParameter("key");
                JsVote vote = new JsVote();
                if (vote != null && !"".equals(vote)) {
                    vote.setKeyname(key);
                }
                String ask = "";
                String age = "0";
                String city = "";
                String phone = "";
                String url = "";
                String qq = "";
                boolean is_exist_key = false;
                String answer = "";
                List<JsVote> voteList = voteDao.findByExample(vote);
                if (voteList != null && voteList.size() > 0) {
                    vote = voteList.get(0);
                    ask = vote.getAsk();
                    age = vote.getAge();
                    city = vote.getCity();
                    phone = vote.getPhone();
                    qq = vote.getQq();
                    url = vote.getUrl();
                    is_exist_key = true;
                    if (vote.getAnswer() != null && !"".equals(vote.getAnswer())) {
                        boolean flag = StringUtil.getHanzi(vote.getAnswer());
                        if (!flag) {
                            try {
                                byte[] bytes = StringUtil.hexDecode(vote.getAnswer());
                                String ObjContent = new String(bytes, "UTF-8");
                                answer = ObjContent;
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }

                JsAsk js_ask = new JsAsk();
                if (ask != null && !"".equals(ask)) {
                    js_ask.setKeyname(ask);
                }
                String topic = "";
                String desc = "";
                String item = "";
                List<JsAsk> alist = askDao.findByExample(js_ask);
                if (alist != null && !"".equals(alist)) {
                    topic = alist.get(0).getTopic();
                    desc = alist.get(0).getDescs();
                    item = alist.get(0).getItem();
                }
                List<AskMsg> askIList = new ArrayList<AskMsg>();
                if (item != null && !"".equals(item)) {
                    try {
                        JSONObject obj = JSONObject.fromObject(item);
                        for (int j = 0; j < 15; j++) {
                            JSONObject ask0 = obj.getJSONObject("ask" + j);
                            if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                String ids0 = "";
                                if (ask.equals("6qn3y")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "h4l1o400t4q5";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "rrt92gv7dwcc";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "28ty52ft51za";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "nxjo4rstlq7b";
                                    } else if (ask0.getString("id").equals("ask4")) {
                                        ids0 = "ep19aomfxsx4";
                                    } else if (ask0.getString("id").equals("ask5")) {
                                        ids0 = "jr0j11fzlvqc";
                                    }
                                }

                                if (ask.equals("18c2k")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "o6psyhf9ezpj";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "miujcud5h3f7";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "x7j4ox1a48fe";
                                    }
                                }

                                if (ask.equals("foj84")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "wdhcvk5nxuhm";
                                    }
                                }

                                if (ask.equals("766o9")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "vxb2ch5uixga";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "nn7155k48o30";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "wap09vb3tl3o";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "ghg0wx9ca60z";
                                    }
                                }

                                String id0 = ask0.getString("id");
                                String topic0 = ask0.getString("topic");
                                JSONArray items0 = ask0.getJSONArray("items");
                                AskMsg askMsg = new AskMsg();
                                askMsg.setId(id0);
                                askMsg.setIds(ids0);
                                askMsg.setTopic(topic0);
                                if (items0 != null && items0.size() > 0) {
                                    List<Items> itemList = new ArrayList<Items>();
                                    for (int i = 0; i < items0.size(); i++) {
                                        Items items = new Items();
                                        JSONObject o = JSONObject.fromObject(items0.get(i));
                                        items.setQ(o.getString("q"));

                                        items.setI(o.getString("i"));
                                        itemList.add(items);
                                    }
                                    askMsg.setItemList(itemList);
                                }
                                askIList.add(askMsg);
                            }
                        }
                        result.setDefaultModel("askIList", askIList);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                result.setDefaultModel("qq", qq);
                result.setDefaultModel("answer", answer);
                result.setDefaultModel("is_exist_key", is_exist_key);
                result.setDefaultModel("item", item);
                result.setDefaultModel("topic", topic);
                result.setDefaultModel("age", age);
                result.setDefaultModel("key", key);
                result.setDefaultModel("city", city);
                result.setDefaultModel("url", url);
                result.setDefaultModel("phone", phone);
                result.setDefaultModel("desc", desc);
                result.setDefaultModel("alist", alist);
                result.setDefaultModel("voteList", voteList);


                return result;
            }
        });

        if (StringUtil.JudgeIsMoblie(request)) {
            return new ModelAndView("admin_t/phone", modelMap);
        } else {
            return new ModelAndView("admin_t/ask", modelMap);
        }
    }


    @RequestMapping(value = "/ask2")
    public ModelAndView ask2(ModelMap modelMap, final BaseVo vo,
                             final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String ask = request.getParameter("ask");
                String url = request.getParameter("url");

                JsAsk js_ask = new JsAsk();
                if (ask != null && !"".equals(ask)) {
                    js_ask.setKeyname(ask);
                }
                String topic = "";
                String desc = "";
                String item = "";
                String spcode = "";
                List<JsAsk> alist = askDao.findByExample(js_ask);
                if (alist != null && !"".equals(alist)) {
                    topic = alist.get(0).getTopic();
                    desc = alist.get(0).getDescs();
                    item = alist.get(0).getItem();
                    spcode = alist.get(0).getKeyname();
                }
                List<AskMsg> askIList = new ArrayList<AskMsg>();
                if (item != null && !"".equals(item)) {
                    try {
                        JSONObject obj = JSONObject.fromObject(item);
                        for (int j = 0; j < 15; j++) {
                            JSONObject ask0 = obj.getJSONObject("ask" + j);
                            if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                String ids0 = "";
                                if (ask.equals("6qn3y")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "h4l1o400t4q5";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "rrt92gv7dwcc";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "28ty52ft51za";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "nxjo4rstlq7b";
                                    } else if (ask0.getString("id").equals("ask4")) {
                                        ids0 = "ep19aomfxsx4";
                                    } else if (ask0.getString("id").equals("ask5")) {
                                        ids0 = "jr0j11fzlvqc";
                                    }
                                }

                                if (ask.equals("18c2k")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "o6psyhf9ezpj";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "miujcud5h3f7";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "x7j4ox1a48fe";
                                    }
                                }

                                if (ask.equals("foj84")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "wdhcvk5nxuhm";
                                    }
                                }

                                if (ask.equals("766o9")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "vxb2ch5uixga";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "nn7155k48o30";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "wap09vb3tl3o";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "ghg0wx9ca60z";
                                    }
                                }

                                String id0 = ask0.getString("id");
                                String topic0 = ask0.getString("topic");
                                JSONArray items0 = ask0.getJSONArray("items");
                                AskMsg askMsg = new AskMsg();
                                askMsg.setId(id0);
                                askMsg.setIds(ids0);
                                askMsg.setTopic(topic0);
                                if (items0 != null && items0.size() > 0) {
                                    List<Items> itemList = new ArrayList<Items>();
                                    for (int i = 0; i < items0.size(); i++) {
                                        Items items = new Items();
                                        JSONObject o = JSONObject.fromObject(items0.get(i));
                                        items.setQ(o.getString("q"));

                                        items.setI(o.getString("i"));
                                        itemList.add(items);
                                    }
                                    askMsg.setItemList(itemList);
                                }
                                askIList.add(askMsg);
                            }
                        }
                        result.setDefaultModel("askIList", askIList);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                result.setDefaultModel("item", item);
                result.setDefaultModel("topic", topic);
                result.setDefaultModel("desc", desc);
                result.setDefaultModel("ask", ask);
                result.setDefaultModel("url", url);
                result.setDefaultModel("alist", alist);
                result.setDefaultModel("spcode", spcode);
                return result;
            }
        });
        return new ModelAndView("admin_t/ask-2", modelMap);
    }

    //异步获取测评结果
    @RequestMapping(value = "/ask_answer_read")
    public ModelAndView ask_answer_read(ModelMap modelMap, final BaseVo vo,
                                        final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String key = request.getParameter("key");

                JsVote vote = new JsVote();
                if (key != null && !"".equals(key)) {
                    vote.setKeyname(key);
                }

                List<JsVote> votelist = voteDao.getVolistAnswer(vote);
                String answer = "";
                String item = "";
                String ask = "";
                String score = "";
                if (votelist != null && votelist.size() > 0) {
                    vote = votelist.get(0);
                    item = votelist.get(0).getItems();
                    ask = votelist.get(0).getAsk();
                    score = votelist.get(0).getScores();
                    if (vote.getAnswer() != null && !"".equals(vote.getAnswer())) {
                        boolean flag = StringUtil.getHanzi(vote.getAnswer());
                        if (!flag) {
                            byte[] bytes = StringUtil.hexDecode(vote.getAnswer());
                            try {
                                String comanswer = new String(bytes, "UTF-8");
                                answer = comanswer;
                            } catch (UnsupportedEncodingException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }

                List<AskMsg> askIList = new ArrayList<AskMsg>();
                if (item != null && !"".equals(item)) {
                    try {
                        JSONObject obj = JSONObject.fromObject(item);
                        for (int j = 0; j < 15; j++) {
                            JSONObject ask0 = obj.getJSONObject("ask" + j);
                            if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                String ids0 = "";
                                if (ask.equals("6qn3y")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "h4l1o400t4q5";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "rrt92gv7dwcc";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "28ty52ft51za";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "nxjo4rstlq7b";
                                    } else if (ask0.getString("id").equals("ask4")) {
                                        ids0 = "ep19aomfxsx4";
                                    } else if (ask0.getString("id").equals("ask5")) {
                                        ids0 = "jr0j11fzlvqc";
                                    }
                                }

                                if (ask.equals("18c2k")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "o6psyhf9ezpj";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "miujcud5h3f7";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "x7j4ox1a48fe";
                                    }
                                }

                                if (ask.equals("foj84")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "wdhcvk5nxuhm";
                                    }
                                }

                                if (ask.equals("766o9")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "vxb2ch5uixga";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "nn7155k48o30";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "wap09vb3tl3o";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "ghg0wx9ca60z";
                                    }
                                }

                                String id0 = ask0.getString("id");
                                String topic0 = ask0.getString("topic");
                                JSONArray items0 = ask0.getJSONArray("items");
                                AskMsg askMsg = new AskMsg();
                                askMsg.setId(id0);
                                askMsg.setIds(ids0);
                                askMsg.setTopic(topic0);
                                if (items0 != null && items0.size() > 0) {
                                    List<Items> itemList = new ArrayList<Items>();
                                    for (int i = 0; i < items0.size(); i++) {
                                        Items items = new Items();
                                        JSONObject o = JSONObject.fromObject(items0.get(i));
                                        items.setQ(o.getString("q"));

                                        items.setI(o.getString("i"));
                                        itemList.add(items);
                                    }
                                    askMsg.setItemList(itemList);
                                }
                                askIList.add(askMsg);
                            }
                        }
                        result.setDefaultModel("askIList", askIList);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }


                List<AskMsg> askSList = new ArrayList<AskMsg>();
                if (score != null && !"".equals(score)) {
                    try {
                        JSONObject obj = JSONObject.fromObject(score);

                        for (int j = 0; j < 15; j++) {
                            JSONObject ask0 = obj.getJSONObject("ask" + j);
                            if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                String ids0 = "";
                                if (ask.equals("6qn3y")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "vj9koshpcqua";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "tx1q2cr60ybl";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "7h8yrl4o2zel";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "arf395ste4ds";
                                    } else if (ask0.getString("id").equals("ask4")) {
                                        ids0 = "kgt1y9gs1iqc";
                                    } else if (ask0.getString("id").equals("ask5")) {
                                        ids0 = "ts7yixfhhhqd";
                                    } else if (ask0.getString("id").equals("ask6")) {
                                        ids0 = "a2gr7b6ozys3";
                                    }
                                }

                                if (ask.equals("18c2k")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "hucspegim6hi";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "6rn1bin3pou1";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "03312d4kb53s";
                                    }
                                }

                                if (ask.equals("foj84")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "2zx0358ab8uk";
                                    }
                                }

                                if (ask.equals("766o9")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "x8frdez6z64k";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "ctqi7ssz4swq";
                                    }
                                }
                                String id = ask0.getString("id");
                                String topic = ask0.getString("topic");
                                JSONArray source = ask0.getJSONArray("source");
                                JSONArray scores = ask0.getJSONArray("scores");
                                AskMsg askMsg = new AskMsg();
                                askMsg.setId(id);
                                askMsg.setIds(ids0);
                                askMsg.setTopic(topic);
                                askMsg.setSource(source);
                                if (scores != null && scores.size() > 0) {
                                    List<Scores> scoresList = new ArrayList<Scores>();
                                    for (int i = 0; i < scores.size(); i++) {
                                        Scores sco = new Scores();
                                        JSONObject o = JSONObject.fromObject(scores.get(i));
                                        sco.setS1(o.getString("s1"));
                                        sco.setS2(o.getString("s2"));
                                        sco.setR(o.getString("r"));
                                        scoresList.add(sco);
                                    }
                                    askMsg.setScoresList(scoresList);
                                }
                                askSList.add(askMsg);
                            }
                        }
                        result.setDefaultModel("askSList", askSList);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }


                result.setDefaultModel("votelist", votelist);
                result.setDefaultModel("answer", answer);

                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }
    /**
     * @Description:问卷推广链接查询
     * @author: Hqd
     * @date: 2017年11月9日 下午3:05:02 
     * @return
     */
    @RequestMapping(value = "/ask_spread_list")
    public ModelAndView ask_spread_list(ModelMap modelMap, final BaseVo vo,
                                        final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String spname = request.getParameter("sp_name");
                String spcode = request.getParameter("sp_code");
                String spuser = request.getParameter("sp_user");
                String spask = request.getParameter("sp_ask");

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                JsSpread spread = new JsSpread();
                if (spname != null && !"".equals(spname)) {
                    spread.setSpname(spname);
                }
                if (spcode != null && !"".equals(spcode)) {
                    spread.setSpcode(spcode);
                }
                if (spuser != null && !"".equals(spuser)) {
                    spread.setSpuser(spuser);
                }
                if (spask != null && !"".equals(spask)) {
                    spread.setSpask(spask);
                }

                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }
                Integer total = spreadDao.getSpCountlistByType(spread);
                Page page = PageUtil.createPage(8, currPage, total);
                List<JsSpread> list = spreadDao.getSpreadlistByType(spread, page);
                if (list != null && list.size() > 0) {
                    for (JsSpread sp : list) {
                        if (sp.getMdate() != null) {
                            sp.setModedate(sdf.format(new Date(sp.getMdate() * 1000)));
                        }
                    }
                }

                List<JsAsk> askList = askDao.findAll(JsAsk.class);

                result.setDefaultModel("spread", spread);
                result.setDefaultModel("page", page);
                result.setDefaultModel("list", list);
                result.setDefaultModel("askList", askList);
                return result;
            }
        });
        return new ModelAndView("admin_t/ask_spread_list", modelMap);
    }

    /**
     * @Description:添加推广链接
     * @author: Hqd
     * @date: 2017年11月9日 上午11:59:23 
     * @return
     */
    @RequestMapping(value = "/spread_add")
    public ModelAndView ask_spread(ModelMap modelMap, final BaseVo vo,
                                   final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");

                JsSpread spread = new JsSpread();
                if (id != null && !"".equals(id)) {
                    spread = spreadDao.findById(JsSpread.class, Long.valueOf(id));
                    result.setDefaultModel("spread", spread);
                }

                List<JsAsk> list = askDao.findAll(JsAsk.class);

                TgUserinfo userinfo = new TgUserinfo();
                List<TgUserinfo> userlist = userinfoDao.getUserlistByType(userinfo);
                result.setDefaultModel("list", list);
                result.setDefaultModel("userlist", userlist);
                return result;
            }
        });
        return new ModelAndView("admin_t/spread_add", modelMap);
    }

    @RequestMapping(value = "/spread_add_go")
    public ModelAndView spread_add_go(ModelMap modelMap,
                                      final BaseVo vo, final HttpServletRequest request,
                                      final HttpServletResponse response) throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String spcode = request.getParameter("spcode");
                String sp_name = request.getParameter("name");
                String ask = request.getParameter("ask");
                String source = request.getParameter("source");
                String user = request.getParameter("user");

                String spco = "";

                JsSpread spread = new JsSpread();
                spread.setName(sp_name);
                spread.setAsk(ask);
                spread.setSource(source);
                spread.setUsername(user);
                if (spcode != null && !"".equals(spcode)) {
                    spread.setSpcode(spcode);
                    spread.setMdate(new Date().getTime() / 1000);
                    JsSpread sp = new JsSpread();
                    sp.setSpcode(spcode);
                    List<JsSpread> spList = spreadDao.findByExample(sp);
                    if (spList != null && spList.size() > 0) {
                        sp = spList.get(0);
                        if (sp != null) {
                            spread.setId(sp.getId());
                            spreadDao.update(spread);
                        }
                    }
                } else {
                    spco = SsiUtils.randomUUID().substring(0, 5);
                    spread.setCdate(new Date().getTime() / 1000);
                    spread.setMdate(new Date().getTime() / 1000);
                    spread.setSpcode(spco);
                    spreadDao.insert(spread);
                    result.setDefaultModel("ask", ask);
                    result.setDefaultModel("spcode", spco);
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }

    @RequestMapping(value = "/getUserListBynickname")
    public ModelAndView getUserListBynickname(ModelMap modelMap,
                                              final BaseVo vo, final HttpServletRequest request,
                                              final HttpServletResponse response) throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String nickname = request.getParameter("nickname");

                TgUserinfo userinfo = new TgUserinfo();
                userinfo.setNickname(nickname);
                List<TgUserinfo> userlist = userinfoDao.getUserlistByType(userinfo);
                if (userlist != null && userlist.size() > 0) {
                    result.setDefaultModel("user", userlist.get(0));
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }
    
    //模糊查找老师姓名
    @RequestMapping(value = "/getUserBynickname")
    public ModelAndView getUserBynickname(ModelMap modelMap,
                                          final BaseVo vo, final HttpServletRequest request,
                                          final HttpServletResponse response) throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String nickname = request.getParameter("nickname");

                TgUserinfo userinfo = new TgUserinfo();
                userinfo.setNickname(nickname);
                userinfo.setJob("课程顾问");
                List<TgUserinfo> userlist = userinfoDao.getUserlistByType(userinfo);
                if (userlist != null && userlist.size() > 0) {
                    result.setDefaultModel("user", userlist.get(0));
                }

                TgUserinfo userinfo1 = new TgUserinfo();
                userinfo1.setNickname(nickname);
                userinfo1.setJob("在线课程顾问");
                List<TgUserinfo> userlist1 = userinfoDao.getUserlistByType(userinfo1);
                if (userlist1 != null && userlist1.size() > 0) {
                    result.setDefaultModel("user", userlist1.get(0));
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }
    
    //问卷调查，网站调查
    @RequestMapping(value = "/from_user_list")
    public ModelAndView from_user_list(ModelMap modelMap, final BaseVo vo,
             final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String phone = request.getParameter("phone");
                String st_type = request.getParameter("st_type");
                String state = request.getParameter("state");
                String startTime = request.getParameter("startTime");
                String endTime = request.getParameter("endTime");
                String type = request.getParameter("type");
                SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
                JsFromUser fromUser = new JsFromUser();
                
                if (phone != null && !"".equals(phone)) {
                    fromUser.setPhone(phone);
                }
                if (st_type != null && !"".equals(st_type)) {
                    fromUser.setSt_type(Integer.valueOf(st_type));
                }
                if (startTime != null && !"".equals(startTime)) {
                    result.setDefaultModel("startTime", startTime);
                    try {
                        fromUser.setStartTime(sd.parse(startTime).getTime() / 1000 + "");
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                if (endTime != null && !"".equals(endTime)) {
                    result.setDefaultModel("endTime", endTime);
                    try {
                        fromUser.setEndTime(DateUtil.getTommorrowDay1(sd.parse(endTime)).getTime() / 1000 + "");
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                if (state != null && !"".equals(state)) {
                    if (state.equals("1")) {
                        fromUser.setRkey1("1");
                    } else if (state.equals("2")) {
                        fromUser.setRkey2("1");
                    }
                    fromUser.setState(state);
                }
                if (type != null && !"".equals(type)) {
                    fromUser.setType(type);
                }
                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }

                Integer total = fromUserDao.getFromUserCountByType(fromUser);
                Page page = PageUtil.createPage(8, currPage, total);
                List<JsFromUser> list = fromUserDao.getFromUserByType(fromUser, page);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                TgUserinfo userinfo = new TgUserinfo();
                TgSource source = new TgSource();
                if (list != null && list.size() > 0) {
                    for (JsFromUser user : list) {
                        if (user.getCreateTime() != null) {
                            user.setcDate(sdf.format(new Date(user.getCreateTime() * 1000)));
                        }
                        if (user.getUsername() != null && !"".equals(user.getUsername())) {
                            userinfo.setUsername(user.getUsername());
                            List<TgUserinfo> userlist = userinfoDao.findByExample(userinfo);
                            if (userlist != null && userlist.size() > 0) {
                                user.setNickname(userlist.get(0).getNickname());
                                ;
                            }
                        }
                        if (user.getSource() != null && !"".equals(user.getSource())) {
                            source.setKeyname(user.getSource());
                            List<TgSource> sourcelist = sourceDao.findByExample(source);
                            if (sourcelist != null && sourcelist.size() > 0) {
                                user.setSource(sourcelist.get(0).getName());
                            }
                        }
                    }
                }
                List<JsFromUser> types = fromUserDao.getTypes();
                result.setDefaultModel("types", types);
                result.setDefaultModel("list", list);
                result.setDefaultModel("page", page);
                result.setDefaultModel("phone", phone);
                result.setDefaultModel("fromUser", fromUser);
                result.setDefaultModel("st_type", st_type);
                result.setDefaultModel("state", state);
                result.setDefaultModel("startTime", startTime);
                result.setDefaultModel("endTime", endTime);
                result.setDefaultModel("type", type);
                return result;
            }
        });
        return new ModelAndView("admin_t/from_user_list", modelMap);
    }
    //问卷调查，网站调查
    @RequestMapping(value = "/wenjuanXz")
    public ModelAndView wenjuanXz(ModelMap modelMap, final BaseVo vo,
       final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String phone = request.getParameter("phone");
                String st_type = request.getParameter("st_type");
                String state = request.getParameter("state");
                String startTime = request.getParameter("startTime");
                String endTime = request.getParameter("endTime");
                String type = request.getParameter("type");
                SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
                JsFromUser fromUser = new JsFromUser();
                if (phone != null && !"".equals(phone)) {
                    fromUser.setPhone(phone);
                }
                if (st_type != null && !"".equals(st_type)) {
                    fromUser.setSt_type(Integer.valueOf(st_type));
                }
                if (startTime != null && !"".equals(startTime)) {
                    result.setDefaultModel("startTime", startTime);
                    try {
                        fromUser.setStartTime(sd.parse(startTime).getTime() / 1000 + "");
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                if (endTime != null && !"".equals(endTime)) {
                    result.setDefaultModel("endTime", endTime);
                    try {
                        fromUser.setEndTime(DateUtil.getTommorrowDay1(sd.parse(endTime)).getTime() / 1000 + "");
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                if (state != null && !"".equals(state)) {
                    if (state.equals("1")) {
                        fromUser.setRkey1("1");
                    } else if (state.equals("2")) {
                        fromUser.setRkey2("1");
                    }
                    fromUser.setState(state);
                }
                if (type != null && !"".equals(type)) {
                    fromUser.setType(type);
                }
                List<JsFromUser> list = fromUserDao.getFromUserByXz(fromUser);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                TgUserinfo userinfo = new TgUserinfo();
                TgSource source = new TgSource();
                if (list != null && list.size() > 0) {
                    for (JsFromUser user : list) {
                        if (user.getCreateTime() != null) {
                            user.setcDate(sdf.format(new Date(user.getCreateTime() * 1000)));
                        }
                        if (user.getUsername() != null && !"".equals(user.getUsername())) {
                            userinfo.setUsername(user.getUsername());
                            List<TgUserinfo> userlist = userinfoDao.findByExample(userinfo);
                            if (userlist != null && userlist.size() > 0) {
                                user.setNickname(userlist.get(0).getNickname());
                                ;
                            }
                        }
                        if (user.getSource() != null && !"".equals(user.getSource())) {
                            source.setKeyname(user.getSource());
                            List<TgSource> sourcelist = sourceDao.findByExample(source);
                            if (sourcelist != null && sourcelist.size() > 0) {
                                user.setSource(sourcelist.get(0).getName());
                            }
                        }
                    }

                }
                List<JsFromUser> types = fromUserDao.getTypes();
                result.setDefaultModel("types", types);
                result.setDefaultModel("list", list);
                result.setDefaultModel("phone", phone);
                
                
                String name = WriterExcel.webwenjuan(list, startTime, endTime);
                result.setDefaultModel("name", name);

                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }
    //分配网站调查
    @RequestMapping(value = "/from_user_allot")
    public ModelAndView from_user_allot(ModelMap modelMap, final BaseVo vo,
                                        final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");
                String look = request.getParameter("look");

                JsVote from = new JsVote();
                if (id != null && !"".equals(id)) {
                    from = jsVoteDao.findById(JsVote.class, Long.valueOf(id));
                    if (from != null) {
                        TgClient client = new TgClient();

                        Long a = 0L;
                        Long b = 0L;
                        Long c = 0L;
                        if (from.getPhone() != null && !"".equals(from.getPhone())) {
                            TgClient client1 = new TgClient();
                            client1.setPhone(from.getPhone());
                            client.setPhone(from.getPhone());
                            a = clientDao.countEqual(client1);
                        }
                        if (from.getEmail() != null && !"".equals(from.getEmail())) {
                            TgClient client2 = new TgClient();
                            client2.setWeixin(from.getEmail());
                            client.setWeixin(from.getEmail());
                            b = clientDao.countEqual(client2);
                        }

                        Long total = a + b + c;
                        if (total > 0) {
                            result.setDefaultModel("total", "1");
                            List<TgClient> clist = clientDao.getClientallot(client);
                            result.setDefaultModel("clist", clist.get(0));
                        }
                    }
                }
                TgUserinfo user = new TgUserinfo();
                user.setJob("课程顾问");
                List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(user);

                TgUserinfo user1 = new TgUserinfo();
                user1.setJob("在线课程顾问");
                List<TgUserinfo> uList1 = userinfoDao.getUserInfoByUserInfo(user1);

                result.setDefaultModel("uList", uList);
                result.setDefaultModel("uList1", uList1);
                result.setDefaultModel("look", look);
                result.setDefaultModel("vote", from);
                return result;
            }
        });
        return new ModelAndView("admin_t/from_user_allot", modelMap);
    }

    //网站分配
    @RequestMapping(value = "/user_allot_go")
    public ModelAndView user_allot_go(ModelMap modelMap,
                                      final BaseVo vo, final HttpServletRequest request,
                                      final HttpServletResponse response) throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("voteId");
                String user = request.getParameter("user");
                String descs = request.getParameter("desc");
                String clientkey = request.getParameter("clientkey");

                TgUser users = UserUtil.getUserFromCookies();
                String regEx = "[^0-9]";
                Pattern pat = Pattern.compile(regEx);

                if (id != null && !"".equals(id)) {
                    JsVote vote = new JsVote();
                    vote = jsVoteDao.findById(JsVote.class, Long.valueOf(id));
                    if (vote != null) {
                        vote.setUsername(user);
                        vote.setTo_time(new Date());
                        vote.setGo_username(users.getUsername());
                        jsVoteDao.update(vote);


                        TgClient client = new TgClient();
                        String keys = SsiUtils.randomUUID();
                        client.setRawusername(vote.getUsername());
                        client.setLodusername(user);
                        client.setNickname(null==vote.getNickname()||(String.valueOf(vote.getNickname()).equals(""))?vote.getSchool():vote.getNickname());
                        if(null==client.getNickname()||client.getNickname().equals("")) {
                        	client.setNickname("匿名");                        
                        }
                        client.setSource(vote.getSource());
                        client.setPhone(vote.getPhone());
                        client.setEmail(vote.getEmail());
                        client.setAddress(vote.getCity());
                        client.setDescs(descs);
                        client.setType(2);
                        client.setFrom_id(vote.getId());
                        client.setCdate(new Date().getTime() / 1000);
                        client.setMdate(new Date().getTime() / 1000);
                        client.setRdate(new Date().getTime() / 1000);
                        client.setUsername(user);
                        client.setCity(vote.getCity());
                        client.setProvince(vote.getProvince());
                        if (clientkey != null && !"".equals(clientkey)) {
                            client.setKeyname(clientkey);
                            clientDao.update(client);
                        } else {
                            client.setKeyname(keys);
                            clientDao.insert(client);

                            TgStudent stu = new TgStudent();
                            stu.setPkey(keys);
                            stu.setKeyname(SsiUtils.randomUUID());

                            Matcher mat = pat.matcher(vote.getAge());
                            String repickStr = mat.replaceAll("").trim();

                            stu.setAge(repickStr);
                            stu.setNickname(vote.getName());
                            stu.setMdate(new Date().getTime() / 1000);
                            studentDao.insert(stu);
                        }
                    }
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }

    //删除问卷
    @RequestMapping(value = "/deleteWenjuanById")
    public ModelAndView deleteWenjuanById(ModelMap modelMap, final BaseVo vo,
            final HttpServletRequest request, final HttpServletResponse response)
            		throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String id = request.getParameter("id");
                if (id != null && !"".equals(id)) {
                    fromUserDao.delete(JsFromUser.class, Long.valueOf(id));
                }
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }


    //问卷测评
    @RequestMapping(value = "/answer_review")
    public ModelAndView answer_review(ModelMap modelMap, final BaseVo vo,
                                      final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String sp = request.getParameter("sp");
                String url = request.getParameter("url");

                //String key = request.getParameter("key");
                //判断key然后取得
                JsSpread spread = new JsSpread();
                if (sp != null && !"".equals(spread)) {
                    spread.setSpcode(sp);
                }
                List<JsSpread> list = spreadDao.findByExample(spread);
                String ask = "";
                if (list != null && list.size() > 0) {
                    spread = list.get(0);
                    ask = spread.getAsk();
                }

                JsAsk js_ask = new JsAsk();
                if (ask != null && !"".equals(ask)) {
                    js_ask.setKeyname(ask);
                }
                String topic = "";
                String desc = "";
                String item = "";
                List<JsAsk> alist = askDao.findByExample(js_ask);
                if (alist != null && !"".equals(alist)) {
                    topic = alist.get(0).getTopic();
                    desc = alist.get(0).getDescs();
                    item = alist.get(0).getItem();
                }
                List<AskMsg> askIList = new ArrayList<AskMsg>();
                if (item != null && !"".equals(item)) {
                    try {
                        JSONObject obj = JSONObject.fromObject(item);
                        for (int j = 0; j < 15; j++) {
                            JSONObject ask0 = obj.getJSONObject("ask" + j);
                            if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                String ids0 = "";
                                if (ask.equals("6qn3y")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "h4l1o400t4q5";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "rrt92gv7dwcc";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "28ty52ft51za";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "nxjo4rstlq7b";
                                    } else if (ask0.getString("id").equals("ask4")) {
                                        ids0 = "ep19aomfxsx4";
                                    } else if (ask0.getString("id").equals("ask5")) {
                                        ids0 = "jr0j11fzlvqc";
                                    }
                                }

                                if (ask.equals("18c2k")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "o6psyhf9ezpj";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "miujcud5h3f7";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "x7j4ox1a48fe";
                                    }
                                }

                                if (ask.equals("foj84")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "wdhcvk5nxuhm";
                                    }
                                }

                                if (ask.equals("766o9")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "vxb2ch5uixga";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "nn7155k48o30";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "wap09vb3tl3o";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "ghg0wx9ca60z";
                                    }
                                }

                                String id0 = ask0.getString("id");
                                String topic0 = ask0.getString("topic");
                                JSONArray items0 = ask0.getJSONArray("items");
                                AskMsg askMsg = new AskMsg();
                                askMsg.setId(id0);
                                askMsg.setIds(ids0);
                                askMsg.setTopic(topic0);
                                if (items0 != null && items0.size() > 0) {
                                    List<Items> itemList = new ArrayList<Items>();
                                    for (int i = 0; i < items0.size(); i++) {
                                        Items items = new Items();
                                        JSONObject o = JSONObject.fromObject(items0.get(i));
                                        items.setQ(o.getString("q"));

                                        items.setI(o.getString("i"));
                                        itemList.add(items);
                                    }
                                    askMsg.setItemList(itemList);
                                }
                                askIList.add(askMsg);
                            }
                        }
                        result.setDefaultModel("askIList", askIList);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (sp != null) {
                    if (sp.equals("F20C5") || sp.equals("4F9C7") || sp.equals("AB46D") || sp.equals("A0C06") || sp.equals("ADB8A")) {
                        String reg = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
                        if (desc.contains("http://mfa.zoosnet.net/LR/Chatpre.aspx?id=MFA54261545&lng=cn")) {
                            desc = desc.replaceAll(reg, "#");
                        }
                    }
                }

                result.setDefaultModel("spcode", sp);
                result.setDefaultModel("url", url);
                result.setDefaultModel("item", item);
                result.setDefaultModel("topic", topic);
                result.setDefaultModel("desc", desc);
                result.setDefaultModel("ask", ask);
                result.setDefaultModel("alist", alist);
                return result;
            }
        });

        if (StringUtil.JudgeIsMoblie(request)) {
            return new ModelAndView("admin_t/phone", modelMap);
        } else {
        	//竞思问卷调查
            return new ModelAndView("admin_t/answer_review", modelMap);
        }
    }
    
  //问卷测评2
    @RequestMapping(value = "/answer_review2")
    public ModelAndView answer_review2(ModelMap modelMap, final BaseVo vo,
                                      final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String sp = request.getParameter("sp");
                String url = request.getParameter("url");

                //String key = request.getParameter("key");
                //判断key然后取得
                JsSpread spread = new JsSpread();
                if (sp != null && !"".equals(spread)) {
                    spread.setSpcode(sp);
                }
                List<JsSpread> list = spreadDao.findByExample(spread);
                String ask = "";
                if (list != null && list.size() > 0) {
                    spread = list.get(0);
                    ask = spread.getAsk();
                }

                JsAsk js_ask = new JsAsk();
                if (ask != null && !"".equals(ask)) {
                    js_ask.setKeyname(ask);
                }
                String topic = "";
                String desc = "";
                String item = "";
                List<JsAsk> alist = askDao.findByExample(js_ask);
                if (alist != null && !"".equals(alist)) {
                    topic = alist.get(0).getTopic();
                    desc = alist.get(0).getDescs();
                    item = alist.get(0).getItem();
                }
                List<AskMsg> askIList = new ArrayList<AskMsg>();
                if (item != null && !"".equals(item)) {
                    try {
                        JSONObject obj = JSONObject.fromObject(item);
                        for (int j = 0; j < 15; j++) {
                            JSONObject ask0 = obj.getJSONObject("ask" + j);
                            if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                String ids0 = "";
                                if (ask.equals("6qn3y")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "h4l1o400t4q5";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "rrt92gv7dwcc";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "28ty52ft51za";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "nxjo4rstlq7b";
                                    } else if (ask0.getString("id").equals("ask4")) {
                                        ids0 = "ep19aomfxsx4";
                                    } else if (ask0.getString("id").equals("ask5")) {
                                        ids0 = "jr0j11fzlvqc";
                                    }
                                }

                                if (ask.equals("18c2k")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "o6psyhf9ezpj";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "miujcud5h3f7";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "x7j4ox1a48fe";
                                    }
                                }

                                if (ask.equals("foj84")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "wdhcvk5nxuhm";
                                    }
                                }

                                if (ask.equals("766o9")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "vxb2ch5uixga";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "nn7155k48o30";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "wap09vb3tl3o";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "ghg0wx9ca60z";
                                    }
                                }

                                String id0 = ask0.getString("id");
                                String topic0 = ask0.getString("topic");
                                JSONArray items0 = ask0.getJSONArray("items");
                                AskMsg askMsg = new AskMsg();
                                askMsg.setId(id0);
                                askMsg.setIds(ids0);
                                askMsg.setTopic(topic0);
                                if (items0 != null && items0.size() > 0) {
                                    List<Items> itemList = new ArrayList<Items>();
                                    for (int i = 0; i < items0.size(); i++) {
                                        Items items = new Items();
                                        JSONObject o = JSONObject.fromObject(items0.get(i));
                                        items.setQ(o.getString("q"));

                                        items.setI(o.getString("i"));
                                        itemList.add(items);
                                    }
                                    askMsg.setItemList(itemList);
                                }
                                askIList.add(askMsg);
                            }
                        }
                        result.setDefaultModel("askIList", askIList);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (sp != null) {
                    if (sp.equals("F20C5") || sp.equals("4F9C7") || sp.equals("AB46D") || sp.equals("A0C06") || sp.equals("ADB8A")) {
                        String reg = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
                        if (desc.contains("http://mfa.zoosnet.net/LR/Chatpre.aspx?id=MFA54261545&lng=cn")) {
                            desc = desc.replaceAll(reg, "#");
                        }
                    }
                }

                result.setDefaultModel("spcode", sp);
                result.setDefaultModel("url", url);
                result.setDefaultModel("item", item);
                result.setDefaultModel("topic", topic);
                result.setDefaultModel("desc", desc);
                result.setDefaultModel("ask", ask);
                result.setDefaultModel("alist", alist);
                return result;
            }
        });

        if (StringUtil.JudgeIsMoblie(request)) {
            return new ModelAndView("admin_t/phone2", modelMap);
        } else {
        	//竞思问卷调查
            return new ModelAndView("admin_t/answer_review", modelMap);
        }
    }

    //添加问卷测评数据
    @RequestMapping(value = "/add_answer_review")
    public ModelAndView add_answer_review(ModelMap modelMap, final BaseVo vo,
                                          final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String age = request.getParameter("age");
                String spcode = request.getParameter("spcode");
                String city = request.getParameter("city");
                String phone = request.getParameter("phone");
                String qq = request.getParameter("qq");
                String email = request.getParameter("email");
                String ask = request.getParameter("ask");
                String ip = request.getParameter("ip");
                String answer = request.getParameter("answer");
                String url = request.getParameter("urls");
                JsVote vote = new JsVote();
                List<JsVote> votelist = null;
                int ask_cn = 0;
                if (phone != null && phone != "") {
                    vote.setPhone(phone);
                    votelist = voteDao.findByExample(vote);
                    if (votelist != null && votelist.size() > 0) {
                        ask_cn = votelist.size();
                    }
                }
                String key = SsiUtils.randomUUID().substring(0, 5);
                if (answer != null && !"".equals(answer)) {
                    byte[] srtbyte = null;
                    try {
                        srtbyte = answer.getBytes("UTF-8");
                        String bytess = StringUtil.toHex(srtbyte);
                        vote.setAnswer(bytess);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
                if (age != null && !"".equals(age)) {
                    vote.setAge(age);
                }
                if (spcode == null && "".equals(spcode)) {
                    spcode = "29nkk";
                }


                vote.setAsk(ask);
                vote.setCity(city);
                vote.setQq(qq);
                vote.setIp(ip);
                vote.setEmail(email);
                vote.setSpcode(spcode);
                vote.setKeyname(key);
                vote.setUrl(url);
                vote.setAsk_cn(ask_cn);
                vote.setCdate(new Date().getTime() / 1000);
                voteDao.insert(vote);

                JsAsk js_ask = new JsAsk();
                if (ask != null && !"".equals(ask)) {
                    js_ask.setKeyname(ask);
                }
                String topic1 = "";
                String desc = "";
                String item = "";
                String score = "";
                List<JsAsk> alist = askDao.findByExample(js_ask);
                if (alist != null && !"".equals(alist)) {
                    topic1 = alist.get(0).getTopic();
                    desc = alist.get(0).getDescs();
                    item = alist.get(0).getItem();
                    score = alist.get(0).getScore();
                }
                List<AskMsg> askIList = new ArrayList<AskMsg>();
                if (item != null && !"".equals(item)) {
                    try {
                        JSONObject obj = JSONObject.fromObject(item);
                        for (int j = 0; j < 15; j++) {
                            JSONObject ask0 = obj.getJSONObject("ask" + j);
                            if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                String ids0 = "";
                                if (ask.equals("6qn3y")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "h4l1o400t4q5";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "rrt92gv7dwcc";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "28ty52ft51za";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "nxjo4rstlq7b";
                                    } else if (ask0.getString("id").equals("ask4")) {
                                        ids0 = "ep19aomfxsx4";
                                    } else if (ask0.getString("id").equals("ask5")) {
                                        ids0 = "jr0j11fzlvqc";
                                    }
                                }

                                if (ask.equals("18c2k")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "o6psyhf9ezpj";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "miujcud5h3f7";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "x7j4ox1a48fe";
                                    }
                                }

                                if (ask.equals("foj84")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "wdhcvk5nxuhm";
                                    }
                                }

                                if (ask.equals("766o9")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "vxb2ch5uixga";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "nn7155k48o30";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "wap09vb3tl3o";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "ghg0wx9ca60z";
                                    }
                                }

                                String id0 = ask0.getString("id");
                                String topic0 = ask0.getString("topic");
                                JSONArray items0 = ask0.getJSONArray("items");
                                AskMsg askMsg = new AskMsg();
                                askMsg.setId(id0);
                                askMsg.setIds(ids0);
                                askMsg.setTopic(topic0);
                                if (items0 != null && items0.size() > 0) {
                                    List<Items> itemList = new ArrayList<Items>();
                                    for (int i = 0; i < items0.size(); i++) {
                                        Items items = new Items();
                                        JSONObject o = JSONObject.fromObject(items0.get(i));
                                        items.setQ(o.getString("q"));
                                        items.setI(o.getString("i"));
                                        itemList.add(items);
                                    }
                                    askMsg.setItemList(itemList);
                                }
                                askIList.add(askMsg);
                            }
                        }
                        result.setDefaultModel("askIList", askIList);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                List<AskMsg> askSList = new ArrayList<AskMsg>();
                if (score != null && !"".equals(score)) {
                    try {
                        JSONObject obj = JSONObject.fromObject(score);

                        for (int j = 0; j < 15; j++) {
                            JSONObject ask0 = obj.getJSONObject("ask" + j);
                            if (ask0 != null && !"null".equals(ask0) && ask0.toString().length() > 10) {
                                String ids0 = "";
                                if (ask.equals("6qn3y")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "vj9koshpcqua";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "tx1q2cr60ybl";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "7h8yrl4o2zel";
                                    } else if (ask0.getString("id").equals("ask3")) {
                                        ids0 = "arf395ste4ds";
                                    } else if (ask0.getString("id").equals("ask4")) {
                                        ids0 = "kgt1y9gs1iqc";
                                    } else if (ask0.getString("id").equals("ask5")) {
                                        ids0 = "ts7yixfhhhqd";
                                    } else if (ask0.getString("id").equals("ask6")) {
                                        ids0 = "a2gr7b6ozys3";
                                    }
                                }

                                if (ask.equals("18c2k")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "hucspegim6hi";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "6rn1bin3pou1";
                                    } else if (ask0.getString("id").equals("ask2")) {
                                        ids0 = "03312d4kb53s";
                                    }
                                }

                                if (ask.equals("foj84")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "2zx0358ab8uk";
                                    }
                                }

                                if (ask.equals("766o9")) {
                                    if (ask0.getString("id").equals("ask0")) {
                                        ids0 = "x8frdez6z64k";
                                    } else if (ask0.getString("id").equals("ask1")) {
                                        ids0 = "ctqi7ssz4swq";
                                    }
                                }
                                String id = ask0.getString("id");
                                String topic = ask0.getString("topic");
                                JSONArray source = ask0.getJSONArray("source");
                                JSONArray scores = ask0.getJSONArray("scores");
                                AskMsg askMsg = new AskMsg();
                                askMsg.setId(id);
                                askMsg.setIds(ids0);
                                askMsg.setTopic(topic);
                                askMsg.setSource(source);
                                if (scores != null && scores.size() > 0) {
                                    List<Scores> scoresList = new ArrayList<Scores>();
                                    for (int i = 0; i < scores.size(); i++) {
                                        Scores sco = new Scores();
                                        JSONObject o = JSONObject.fromObject(scores.get(i));
                                        sco.setS1(o.getString("s1"));
                                        sco.setS2(o.getString("s2"));
                                        sco.setR(o.getString("r"));
                                        scoresList.add(sco);
                                    }
                                    askMsg.setScoresList(scoresList);
                                }
                                askSList.add(askMsg);
                            }
                        }
                        result.setDefaultModel("askSList", askSList);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                //邮件发送
                if (!StringUtil.isEmpty(qq) && MailUtils.checkEmaile(qq)) {
                    String projectUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
                    String content = projectUrl + "admin/ask.htm?key=" + key;
                    try {
                        MailUtils.sendEmail(qq, "测评结果:", content, "竞思-注意力训练机构");
                    } catch (Exception e) {
                    }
                }

                result.setDefaultModel("key", key);
                result.setDefaultModel("item", item);
                result.setDefaultModel("answer", answer);
                result.setDefaultModel("topic", topic1);
                result.setDefaultModel("desc", desc);
                result.setDefaultModel("alist", alist);
                return result;
            }
        });
        return new ModelAndView("", modelMap);
    }

    /**
     * 三张表合并需要显示的页面
     *
     * @param modelMap
     * @param vo
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/ask_answer_list_new")
    public ModelAndView structInfoNew(ModelMap modelMap, final BaseVo vo,
                                      final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String contact = request.getParameter("contact");
                String weixin = request.getParameter("weixin");
                String address = request.getParameter("address");
                String money = request.getParameter("money");
                String money2 = request.getParameter("money2");
                String source = request.getParameter("source");
                String startTime = request.getParameter("stardate");
                String endTime = request.getParameter("enddate");
                String state = request.getParameter("state");
                String st_type = request.getParameter("st_type");
                String spname = request.getParameter("spname");

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                JsVote vote = new JsVote();
                if (contact != null && !"".equals(contact)) {
                    vote.setPhone(contact);
                }
                if (spname != null && !"".equals(spname)) {
                    vote.setSpname(spname);
                }
                if (weixin != null && !"".equals(weixin)) {
                    vote.setWeixin(weixin);
                }
                if (address != null && !"".equals(address)) {
                    vote.setCity(address);
                }
                if (money != null && !"".equals(money)) {
                    String reg = "^\\d+$";
                    if (money.matches(reg)) {
                        vote.setMoney(Double.valueOf(money));
                    }
                }
                if (money2 != null && !"".equals(money2)) {
                    String reg = "^\\d+$";
                    if (money2.matches(reg)) {
                        vote.setMoney2(Double.valueOf(money2));
                    }
                }
                if (source != null && !"".equals(source)) {
                    vote.setSource(source);
                }
                if (st_type != null && !"".equals(st_type)) {
                    vote.setSt_type(Integer.valueOf(st_type));
                }
                if (startTime != null && !"".equals(startTime)) {
                    result.setDefaultModel("startTime", startTime);
                    try {
                        vote.setStartTime(sdf.parse(startTime).getTime() / 1000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (endTime != null && !"".equals(endTime)) {
                    result.setDefaultModel("endTime", endTime);
                    try {
                        vote.setEndTime(sdf.parse(endTime).getTime() / 1000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (state != null && !"".equals(state)) {
                    if (state.equals("1")) {
                        vote.setState1(state);
                    } else if (state.equals("2")) {
                        vote.setState2(state);
                    }
                }

                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }
                Integer total = voteDao.getVoCountByTypeNew(vote);
                Page page = PageUtil.createPage(8, currPage, total);
                List<JsVote> list = voteDao.getVolistByTypeNew(vote, page);
                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                TgSource source2 = new TgSource();
                for (JsVote jsVote : list) {
                    if (jsVote.getSourceTable() == 1 || jsVote.getSourceTable() == 3) {
                        if (jsVote.getTo_username() != null && !"".equals(jsVote.getTo_username())) {
                            TgUserinfo info = new TgUserinfo();
                            info.setUsername(jsVote.getTo_username());
                            List<TgUserinfo> infoList = userinfoDao.findByExample(info);
                            if (infoList != null && infoList.size() > 0) {
                                String nickname = infoList.get(0).getNickname();
                                jsVote.setTo_username(nickname);
                            }
                        }
                        if (jsVote.getSourceTable() == 1 && jsVote.getType() != null && !"".equals(jsVote.getType())) {
                            source2.setKeyname(jsVote.getType());
                            List<TgSource> souList = sourceDao.findByExample(source2);
                            if (souList != null && souList.size() > 0) {
                                String Type = souList.get(0).getName();
                                jsVote.setType(Type);
                            }
                        }
                    }
                }


                if (list != null && list.size() > 0) {
                    for (JsVote vo : list) {

                        if (vo.getType() != null && !"".equals(vo.getType())) {
                            if (vo.getType().equals("k4jmt5lbp8ne")) {// 400电话
                                vo.setType("400电话");
                            } else if (vo.getType().equals("baiduxunke")) {// 百度寻客
                                vo.setType("百度寻客");
                            } else if (vo.getType().equals("frvmppoifgmb")) {// 今日头条
                                vo.setType("今日头条");
                            } else if (vo.getType().equals("lixianbao")) {// 离线宝
                                vo.setType("离线宝");
                            } else if (vo.getType().equals("shangqiaogt")) {// 商桥沟通客户
                                vo.setType("商桥沟通客户");
                            } else if (vo.getType().equals("edhhjon7t6za")) {// 商桥留言
                                vo.setType("商桥留言");
                            } else if (vo.getType().equals("yunxiaoke")) {// 云销客
                                vo.setType("云销客");
                            } else if (vo.getType().equals("02FAC12A4746")) { //百度糯米
                                vo.setType("百度糯米");
                            } else if (vo.getType().equals("4D189169D77E")) { //百度信息流
                                vo.setType("百度信息流");
                            }
                        }

                        if (vo.getCdate() != null) {
                            vo.setCreateTime(sdf1.format(new Date(vo.getCdate() * 1000)));
                        }
                    }

                }

                result.setDefaultModel("vote", vote);
                result.setDefaultModel("page", page);
                result.setDefaultModel("money", money);
                result.setDefaultModel("spname", spname);
                result.setDefaultModel("source", source);
                result.setDefaultModel("address", address);
                result.setDefaultModel("list", list);
                result.setDefaultModel("contact", contact);
                result.setDefaultModel("startTime", startTime);
                result.setDefaultModel("endTime", endTime);
                result.setDefaultModel("weixin", weixin);
                return result;
            }
        });
        return new ModelAndView("admin_t/ask_answer_list_new", modelMap);
    }


    @RequestMapping(value = "/ask_export_excel")
    public String exportExcel(final BaseVo vo, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        return WriterExcel.exportVoteExcel(request, response, voteDao, vo);
    }

    /**
     * 三张表合并需要显示的页面
     */
    @RequestMapping(value = "/ask_answer_list_market")
    public ModelAndView structInfoMarket(ModelMap modelMap, final BaseVo vo,
                                         final HttpServletRequest request, final HttpServletResponse response)
            throws Exception {
        modelMap = WebExecutor.execute(logger, vo, new Biz() {
            public Result process() {
                Result result = new ResultSupport(true);
                String contact = request.getParameter("contact");
                String weixin = request.getParameter("weixin");
                String address = request.getParameter("address");
                String money = request.getParameter("money");
                String money2 = request.getParameter("money2");
                String source = request.getParameter("source");
                String stardate = request.getParameter("stardate");
                String enddate = request.getParameter("enddate");
                String state = request.getParameter("state");
                String invalid = request.getParameter("st_type");
                String spname = request.getParameter("spname");
                String state_s = request.getParameter("state_s");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                TgClient client=new TgClient();
                if (contact != null && !"".equals(contact)) {
                	client.setPhone(contact);
                }
                if (spname != null && !"".equals(spname)) {
                	TgUserinfo userinfo=new TgUserinfo();
                	userinfo.setNickname(spname);
                	List<TgUserinfo> userinfoList=userinfoDao.findByExample(userinfo);
                	if(userinfoList!=null&&userinfoList.size()>0) {
                		client.setRawusername(userinfoList.get(0).getUsername());
                	}
                }
                if (weixin != null && !"".equals(weixin)) {
                	client.setWeixin(weixin);
                }
                if (address != null && !"".equals(address)) {
                	client.setCity(address);
                }
                if (money != null && !"".equals(money)) {
                    String reg = "^\\d+$";
                    if (money.matches(reg)) {
                    	client.setMoney(Double.valueOf(money));
                    }
                }
                if (money2 != null && !"".equals(money2)) {
                    String reg = "^\\d+$";
                    if (money2.matches(reg)) {
                    	client.setMoney2(Double.valueOf(money2));
                    }
                }
                if (source != null && !"".equals(source)) {
                	client.setSource(source);
                }
                if (invalid != null && !"".equals(invalid)) {
                	if(invalid.equals("1")) {
                		client.setInvalid(0);
                	}else if(invalid.equals("2")) {
                		client.setInvalid(1);
                	}
                }
                if (stardate != null && !"".equals(stardate)) {
                    result.setDefaultModel("stardate", stardate);
                    try {
                    	client.setStartTime(sdf.parse(stardate+" 00:00:00").getTime() / 1000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (enddate != null && !"".equals(enddate)) {
                    result.setDefaultModel("enddate", enddate);
                    try {
                    	client.setEndTime(sdf.parse(enddate+" 23:59:59").getTime() / 1000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (state != null && !"".equals(state)) {
                    if (state.equals("1")) {
                    	client.setState1(state);
                    } else if (state.equals("2")) {
                    	client.setState2(state);
                    }
                }
                if(source!=null && !source.equals("")){
					if("ct5yq4jhc6c7".equals(source)){
						client.setSname("市场部推广(讲座),市场部推广(地推),市场部推广(交换资源)");
					}
				}else{
					client.setSname("公益讲座,市场部推广(讲座),市场部推广(地推),市场部推广(交换资源),传单派发,市场部问卷,公益微课");
				}
                if ((state_s != null && !"".equals(state_s))) {
                    if (state_s.equals("已预约")) {
                    	client.setRenum(2);
                    	client.setRemin(1);
                    } else if (state_s.equals("未出现")) {
                    	client.setRenum(3);
                    	client.setRemin(3);
                    } else if (state_s.equals("已缴费")) {
                    	client.setRecenum(6);
                    	client.setRecemin(6);
                    } else if (state_s.equals("已测评")) {
                    	client.setRecenum(5);
                    	client.setRecemin(1);
                    }
                }
                Integer currPage = 1;
                if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
                    currPage = vo.getCurrPage();
                }
                
                Integer total=clientDao.getClientCountMarket(client);
                Page page = PageUtil.createPage(8, currPage, total);
                List<TgClient> list=clientDao.getClientlistMarket(client,page);
                TgSource source2 = new TgSource();
                for (TgClient clientList : list) {
                        if (clientList.getUsername() != null && !"".equals(clientList.getUsername())) {
                            TgUserinfo info = new TgUserinfo();
                            info.setUsername(clientList.getUsername());
                            List<TgUserinfo> infoList = userinfoDao.findByExample(info);
                            if (infoList != null && infoList.size() > 0) {
                                String nickname = infoList.get(0).getNickname();
                                clientList.setUsername(nickname);
                            }
                        }
                        if(clientList.getRawusername() != null && !"".equals(clientList.getRawusername())) {
                        	 TgUserinfo info = new TgUserinfo();
                        	 info.setUsername(clientList.getRawusername());
                             List<TgUserinfo> infoList = userinfoDao.findByExample(info);
                             if (infoList != null && infoList.size() > 0) {
                                 String nickname = infoList.get(0).getNickname();
                                 clientList.setRawusername(nickname);
                             }
                        }
                        if (clientList.getType() != null && !"".equals(clientList.getType())) {
                            source2.setKeyname(String.valueOf(clientList.getType()));
                            List<TgSource> souList = sourceDao.findByExample(source2);
                            if (souList != null && souList.size() > 0) {
                                String Type = souList.get(0).getName();
                                clientList.setType(Integer.valueOf(Type));
                            }
                        }
                        if (clientList.getCdate() != null) {
                        	clientList.setCreatetime(String.valueOf(sdf.format(new Date(clientList.getCdate() * 1000))));
                        }
                    //查询跟踪个数
                    clientList.setTrackings((long)jsVoteDao.getTrackings(clientList.getKeyname()));
                    //客户状态
                    String stat = null;
                    if (clientList.getState() != null && !"".equals(clientList.getState())) {
                        int renum = Integer.valueOf(clientList.getState());
                        if (renum >= 1 && renum <= 2) {
                            stat = "已预约";
                        } else if (renum == 3) {
                            stat = "未出现";
                        }
                        clientList.setStates(stat);
                    }

                    if (clientList.getWorth() != null && !"".equals(clientList.getWorth())) {
                        Integer recenum = clientList.getWorth();
                        if (recenum == 6) {
                            if (stat != "") {
                                stat = stat + "," + "已缴费";
                            } else {
                                stat = "已缴费";
                            }
                        } else if (0 < recenum && recenum <= 5) {
                            if (stat != "") {
                                stat = stat + "," + "已测评";
                            } else {
                                stat = "已测评";
                            }
                        }
                        clientList.setStates(stat);
                    }

                    if ( clientList.getLast_track() != null && !"".equals( clientList.getLast_track())) {
                    	clientList.setLast_track(clientList.getLast_track().replace("&nbsp;","").trim());
                    	if(StringUtil.isNum(clientList.getLast_track())){
                    		clientList.setFallow(clientList.getLast_track());
                    	}else{
                    		boolean flag = StringUtil.getHanzi(clientList.getLast_track().replaceAll("</?[^<]+>", ""));
                    		if (!flag) {
                    			byte[] bytes = StringUtil.hexDecode(clientList.getLast_track());
                    			String ObjContent;
								try {
									ObjContent = new String(bytes,"UTF-8");
									clientList.setFallow(ObjContent);
								} catch (Exception e) {
									e.printStackTrace();
								}
                    		}else {
                    			clientList.setFallow(clientList.getLast_track());
                    		}
                    	}
                    	if(clientList.getFallow().contains("\"")){
                    		clientList.setFallow(clientList.getFallow().replace('"',' '));
                    	}
                }
				} 
                result.setDefaultModel("client", client);
                result.setDefaultModel("page", page);
                result.setDefaultModel("money", money);
                result.setDefaultModel("spname", spname);
                result.setDefaultModel("source", source);
                result.setDefaultModel("address", address);
                result.setDefaultModel("list", list);
                result.setDefaultModel("contact", contact);
                result.setDefaultModel("stardate", stardate);
                result.setDefaultModel("enddate", enddate);
                result.setDefaultModel("weixin", weixin);
                result.setDefaultModel("state_s", state_s);
                result.setDefaultModel("invalid", invalid);
                return result;
            }
        });
        return new ModelAndView("admin_t/ask_answer_list_market", modelMap);
    }

    /**
     * 检验当前ip是否超出提交次数
     * @param ip
     * @param response
     */
    @RequestMapping(value = "/ajaxLimitIp")
    public void  ajaxLimitIp(String ip,HttpServletResponse response) {
        JsVote vote2 = new JsVote();
        vote2.setIp(ip);
        Integer ipCount = voteDao.limitIP(vote2);
        if (ipCount > 3) {
            try {
                PrintWriter writer = response.getWriter();
                writer.print(ipCount);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
